//
//  LSXQView.m
//  yonghu
//
//  Created by mac on 2018/3/20.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "LSXQView.h"
#import "YHPJViewController.h"
@implementation LSXQView

-(void)creatView{
    self.backgroundColor=_LightGrey;
    _scrollView=[UIScrollView new];
    [self addSubview:_scrollView];
    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    _scrollView.scrollsToTop =NO;
    
    _scrollView.showsVerticalScrollIndicator = FALSE;
    _scrollView.showsHorizontalScrollIndicator = FALSE;
    _scrollView.bounces = NO;
    if (@available(iOS 11.0, *)) {
        self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.viewController.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    
    UIView *topView=[UIView new];
    [_scrollView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.top.mas_equalTo(NAV_HEIGHT+10);
        make.width.mas_equalTo(_mainW-10);
        make.height.mas_equalTo(190);
    }];
    [self creatTopView:topView];
    [self creatJieShaoView];
}

-(void)creatTopView:(UIView *)topView{

    topView.layer.cornerRadius=5;
    topView.backgroundColor=[UIColor whiteColor];
    
    UIImageView *imageview=[UIImageView new];
    [topView addSubview:imageview];
    [imageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(10);
        make.width.height.mas_equalTo(60);
    }];
    imageview.layer.cornerRadius=3;
    NSString *waiter_icon=[_dic objectForKey:@"waiter_icon"];
    NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",_addressUrl,waiter_icon]];
    [imageview sd_setImageWithURL:url];
    
    UILabel *nameLabel=[UILabel new];
    [topView addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imageview.mas_right).mas_equalTo(6);
        make.top.mas_equalTo(imageview);
    }];
    nameLabel.text=[_dic objectForKey:@"waiter_name"];
    nameLabel.textColor=ColorWithRGB(49, 49, 49);
    nameLabel.font=[UIFont systemFontOfSize:17];
    
    NSNumber *evaluate_score=[_dic objectForKey:@"waiter_score"];
    UILabel *coreLabel=[UILabel new];
    [topView addSubview:coreLabel];
    [coreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.centerY.mas_equalTo(nameLabel);
    }];
    coreLabel.text=[NSString stringWithFormat:@"%@分",evaluate_score];
    coreLabel.font=[UIFont systemFontOfSize:15];
    coreLabel.textColor=ColorWithRGB(149, 149, 149);
    
    
    int typeNum2=evaluate_score.doubleValue*10;
    int typeNum=typeNum2%10;
    int index=5-evaluate_score.floatValue;
    
    
    for (int i=0; i<5; i++) {
        UIImageView *xingImage=[UIImageView new];
        [topView addSubview:xingImage];
        [xingImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-40-25*i);
            make.height.width.mas_equalTo(20);
            make.centerY.mas_equalTo(nameLabel);
        }];
        
        if (typeNum>0) {
            if (i<index) {
                xingImage.image=[UIImage imageNamed:@"评分1"];
            }
            if (i==index) {
                xingImage.image=[UIImage imageNamed:@"评分3"];
            }
            if (i>index) {
                xingImage.image=[UIImage imageNamed:@"评分2"];
            }
        }
        else{
            if (i<index) {
                xingImage.image=[UIImage imageNamed:@"评分1"];
            }
            else{
                xingImage.image=[UIImage imageNamed:@"评分2"];
            }
        }
    }
    
    UILabel *pingFen=[UILabel new];
    [topView addSubview:pingFen];
    [pingFen mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(nameLabel);
        make.right.mas_equalTo(-170);
    }];
    pingFen.text=@"综合评分:";
    pingFen.textColor=ColorWithRGB(149, 149, 149);
    pingFen.font=[UIFont systemFontOfSize:16];
    
    NSNumber *wl_length=[_dic objectForKey:@"wl_length"];
    NSString *str=[NSString stringWithFormat:@"执业%@年",wl_length];
    
    CGSize size=[ZQTools getNSStringWeight:str andViewWight:20 andFont:16];
    
    UILabel *label2=[UILabel new];
    [topView addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(nameLabel);
        make.top.mas_equalTo(nameLabel.mas_bottom).mas_equalTo(15);
        make.width.mas_equalTo(size.width+25);
        make.height.mas_equalTo(25);
    }];
    label2.textAlignment=NSTextAlignmentCenter;
    label2.textColor=[UIColor whiteColor];
    label2.text=str;
    label2.font=[UIFont systemFontOfSize:16];
    label2.backgroundColor=ColorWithRGB(75, 168, 220);
    label2.layer.cornerRadius=4;
    
    
    UIImageView *addImage=[UIImageView new];
    [topView addSubview:addImage];
    [addImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(nameLabel);
        make.top.mas_equalTo(label2.mas_bottom).mas_equalTo(15);
        make.width.mas_equalTo(15);
        make.height.mas_equalTo(20);
    }];
    addImage.image=[UIImage imageNamed:@"location"];
    
    UILabel *label=[UILabel new];
    [topView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addImage.mas_right).mas_equalTo(20);
        make.centerY.mas_equalTo(addImage);
    }];
    label.text=[_dic objectForKey:@"wl_city_name"];
    label.font=[UIFont systemFontOfSize:17];
    label.textColor=ColorWithRGB(149, 149, 149);
    
    
    NSString *wl_practice=[_dic objectForKey:@"wl_practice"];
    UILabel *wl_practiceLabel=[UILabel new];
    [topView addSubview:wl_practiceLabel];
    [wl_practiceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(nameLabel);
        make.top.mas_equalTo(addImage.mas_bottom).mas_equalTo(10);
    }];
    wl_practiceLabel.textColor=ColorWithRGB(149, 149, 149);
    wl_practiceLabel.text=[NSString stringWithFormat:@"执业证号:%@",wl_practice];
    wl_practiceLabel.font=[UIFont systemFontOfSize:16];
    
    CGFloat width = 0.0;
    NSString *wl_field_names=[_dic objectForKey:@"wl_field_names"];
    NSArray *biaoQian=[wl_field_names componentsSeparatedByString:@","];
    for (int i=0; i<biaoQian.count; i++) {
        NSString *biaoStr=biaoQian[i];
        CGSize size2=[ZQTools getNSStringWeight:biaoStr andViewWight:16 andFont:16 ];
        
        UILabel *label3=[UILabel new];
        [topView addSubview:label3];
        [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(nameLabel.mas_left).mas_equalTo(width);
            make.height.mas_equalTo(20);
            make.width.mas_equalTo(size2.width+16);
            make.top.mas_equalTo(wl_practiceLabel.mas_bottom).mas_equalTo(15);
        }];
        label3.text=biaoQian[i];
        label3.font=[UIFont systemFontOfSize:16];
        label3.textColor=ColorWithRGB(149, 149, 149);
        label3.layer.cornerRadius=4;
        label3.layer.borderColor=ColorWithRGB(149,149, 149).CGColor;
        label3.layer.borderWidth=1;
        label3.textAlignment=NSTextAlignmentCenter;
        width=width+size2.width+30;
    }
}

-(void)creatJieShaoView{
    [_JieShaoView removeFromSuperview];
    
    _JieShaoView=[UIView new];
    [_scrollView addSubview:_JieShaoView];
    [_JieShaoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.width.mas_equalTo(_mainW-10);
        make.height.mas_equalTo(180);
        make.top.mas_equalTo(210+NAV_HEIGHT);
    }];
    _JieShaoView.backgroundColor=[UIColor whiteColor];
    _JieShaoView.layer.cornerRadius=5;
    
    UIView *xianView=[UIView new];
    [_JieShaoView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(10);
        make.width.mas_equalTo(4);
        make.height.mas_equalTo(20);
    }];
    xianView.backgroundColor=_backgroundColor;
    
    UILabel *woDeLabel=[UILabel new];
    [_JieShaoView addSubview:woDeLabel];
    [woDeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(xianView);
        make.left.mas_equalTo(xianView.mas_right).mas_equalTo(10);
    }];
    woDeLabel.text=@"律师介绍";
    woDeLabel.textColor=ColorWithRGB(49, 49, 49);
    woDeLabel.font=[UIFont systemFontOfSize:22];
    
    
    NSString *document_content=[_dic objectForKey:@"wl_profile"];
    
    
    CGSize size2=[ZQTools getNSStringSize:document_content andViewWight:_mainW-30 andFont:16];
    
    UILabel *contentLabel=[UILabel new];
    [_JieShaoView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(xianView.mas_bottom).mas_equalTo(15);
    }];
    contentLabel.numberOfLines=3;
    contentLabel.text=document_content;
    contentLabel.textColor=ColorWithRGB(149, 149, 149);
    contentLabel.font=[UIFont systemFontOfSize:16];
    
    if (size2.height>90) {
        contentLabel.numberOfLines=5;
        UIImageView *imageView2=[UIImageView new];
        [_JieShaoView addSubview:imageView2];
        [imageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.bottom.mas_equalTo(-5);
            make.width.mas_equalTo(22);
            make.height.mas_equalTo(14);
        }];
        imageView2.image=[UIImage imageNamed:@"展开"];
    
        
        UIView *anView=[UIView new];
        [_JieShaoView addSubview:anView];
        [anView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(0);
            make.top.mas_equalTo(contentLabel);
        }];
        anView.userInteractionEnabled=YES;
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(creatJieShaoView2)];
        [anView addGestureRecognizer:tapGesture];
    }
    
    
    NSArray *evaluate=[_dic objectForKey:@"evaluate"];
    if (evaluate==nil||evaluate.count==0) {
        _scrollView.contentSize = CGSizeMake(0,550);
        return;
    }
    [self creatPingJiaView:_JieShaoView];
    _scrollView.contentSize = CGSizeMake(0,820);
}
-(void)creatJieShaoView2{
    
    [_JieShaoView removeFromSuperview];
    
    NSString *document_content=[_dic objectForKey:@"wl_profile"];
    
    
    CGSize size2=[ZQTools getNSStringSize:document_content andViewWight:_mainW-30 andFont:16];
    
    _JieShaoView=[UIView new];
    [_scrollView addSubview:_JieShaoView];
    [_JieShaoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.width.mas_equalTo(_mainW-10);
        make.height.mas_equalTo(size2.height+60);
        make.top.mas_equalTo(210+NAV_HEIGHT);
    }];
    _JieShaoView.backgroundColor=[UIColor whiteColor];
    _JieShaoView.layer.cornerRadius=5;
    
    UIView *xianView=[UIView new];
    [_JieShaoView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(10);
        make.width.mas_equalTo(4);
        make.height.mas_equalTo(20);
    }];
    xianView.backgroundColor=_backgroundColor;
    
    UILabel *woDeLabel=[UILabel new];
    [_JieShaoView addSubview:woDeLabel];
    [woDeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(xianView);
        make.left.mas_equalTo(xianView.mas_right).mas_equalTo(10);
    }];
    woDeLabel.text=@"律师介绍";
    woDeLabel.textColor=ColorWithRGB(49, 49, 49);
    woDeLabel.font=[UIFont systemFontOfSize:22];
    
    
  
    
    UILabel *contentLabel=[UILabel new];
    [_JieShaoView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(xianView.mas_bottom).mas_equalTo(15);
    }];
    contentLabel.numberOfLines=3;
    contentLabel.text=document_content;
    contentLabel.textColor=ColorWithRGB(149, 149, 149);
    contentLabel.font=[UIFont systemFontOfSize:16];
    
    contentLabel.numberOfLines=0;
    UIImageView *imageView2=[UIImageView new];
    [_JieShaoView addSubview:imageView2];
    [imageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.bottom.mas_equalTo(-5);
        make.width.mas_equalTo(22);
        make.height.mas_equalTo(14);
    }];
    imageView2.image=[UIImage imageNamed:@"收起"];
    
    
    UIView *anView=[UIView new];
    [_JieShaoView addSubview:anView];
    [anView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(contentLabel);
    }];
    anView.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(creatJieShaoView)];
    [anView addGestureRecognizer:tapGesture];
    
    NSArray *evaluate=[_dic objectForKey:@"evaluate"];
    if (evaluate==nil||evaluate.count==0) {
         _scrollView.contentSize = CGSizeMake(0,500+size2.height);
        return;
    }
    [self creatPingJiaView:_JieShaoView];
    _scrollView.contentSize = CGSizeMake(0,700+size2.height);
}
-(void)creatPingJiaView:(UIView *)jieShaoView{
    
    [_pingJiaView removeFromSuperview];
    int abc=0;
    NSArray *evaluate=[_dic objectForKey:@"evaluate"];
    abc=(int)evaluate.count;
    if (evaluate.count>=2) {
        abc=2;
    }
    _pingJiaView=[UIView new];
    [_scrollView addSubview:_pingJiaView];
    [_pingJiaView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(jieShaoView);
        make.top.mas_equalTo(jieShaoView.mas_bottom).mas_equalTo(10);
        make.height.mas_equalTo(abc*120+80);
    }];
    _pingJiaView.backgroundColor=[UIColor whiteColor];
    _pingJiaView.layer.cornerRadius=5;
    
    UIView *titleView=[UIView new];
    [_pingJiaView addSubview:titleView];
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    titleView.userInteractionEnabled=YES;
    _pingJiaView.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushYHPJViewController:)];
    [_pingJiaView addGestureRecognizer:tapGesture];
    
    
    UIView *xianView=[UIView new];
    [titleView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(24);
        make.width.mas_equalTo(3);
    }];
    xianView.backgroundColor=_backgroundColor;
    
    UILabel *titleLabel=[UILabel new];
    [titleView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(xianView.mas_right).mas_equalTo(7);
        make.centerY.mas_equalTo(0);
    }];
    titleLabel.text=@"客户评价";
    titleLabel.font=[UIFont systemFontOfSize:15];
    titleLabel.textColor=ColorWithRGB(90, 90, 90);
    
    UIImageView *imageView=[UIImageView new];
    [titleView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(20);
    }];
    imageView.image=[UIImage imageNamed:@"更多"];
    
    for (int i=0; i<abc; i++) {
        
        NSDictionary *dic=evaluate[i];
        UIView *view=[UIView new];
        [_pingJiaView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(xianView.mas_bottom).mas_equalTo(10+i*120);
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(120);
        }];
        UIImageView *imageView=[UIImageView new];
        [view addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10);
            make.top.mas_equalTo(10);
            make.height.width.mas_equalTo(40);
        }];
        imageView.layer.masksToBounds=YES;
        imageView.layer.cornerRadius=20;
        NSString *user_icon=[dic objectForKey:@"user_icon"];
        user_icon=[NSString stringWithFormat:@"%@%@",_addressUrl,user_icon];
        NSURL *url=[NSURL URLWithString:user_icon];
        [imageView sd_setImageWithURL:url];
        
        
        UILabel *nameLabel=[UILabel new];
        [view addSubview:nameLabel];
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(imageView.mas_right).mas_equalTo(10);
            make.centerY.mas_equalTo(imageView);
        }];
        nameLabel.text=[dic objectForKey:@"user_nickname"];
        nameLabel.font=[UIFont systemFontOfSize:16];
        nameLabel.textColor=ColorWithRGB(49, 49, 49);
        NSNumber *evaluate_score=[dic objectForKey:@"evaluate_score"];
        int typeNum2=evaluate_score.doubleValue*10;
        int typeNum=typeNum2%10;
        int index=5-evaluate_score.floatValue;

        
        for (int j=0; j<5; j++) {
            
            UIImageView *xingImage=[UIImageView new];
            [_pingJiaView addSubview:xingImage];
            [xingImage mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(-10-25*j);
                make.height.width.mas_equalTo(20);
                make.centerY.mas_equalTo(nameLabel);
            }];
            
            if (typeNum>0) {
                if (j<index) {
                    xingImage.image=[UIImage imageNamed:@"评分1"];
                }
                if (j==index) {
                    xingImage.image=[UIImage imageNamed:@"评分3"];
                }
                if (j>index) {
                    xingImage.image=[UIImage imageNamed:@"评分2"];
                }
            }
            else{
                if (j<index) {
                    xingImage.image=[UIImage imageNamed:@"评分1"];
                }
                else{
                    xingImage.image=[UIImage imageNamed:@"评分2"];
                }
            }
        }
        
        UILabel *pingFen=[UILabel new];
        [_pingJiaView addSubview:pingFen];
        [pingFen mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(nameLabel);
            make.right.mas_equalTo(-140);
        }];
        pingFen.text=@"评分:";
        pingFen.textColor=ColorWithRGB(149, 149, 149);
        pingFen.font=[UIFont systemFontOfSize:16];
        NSString *evaluate_content=[dic objectForKey:@"evaluate_content"];
        
        UILabel *lable12=[UILabel new];
        [_pingJiaView addSubview:lable12];
        [lable12 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(xianView);
            make.right.mas_equalTo(-10);
            make.top.mas_equalTo(imageView.mas_bottom).mas_equalTo(10);
        }];
        lable12.textColor=ColorWithRGB(79, 79, 79);
        lable12.text=evaluate_content;
        lable12.font=[UIFont systemFontOfSize:17];
        lable12.numberOfLines=3;
        
        
    }
    for (int i=1; i<abc; i++) {
        UIView *XianView12=[UIView new];
        [_pingJiaView addSubview:XianView12];
        [XianView12 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10);
            make.right.mas_equalTo(-10);
            make.height.mas_equalTo(1);
            make.top.mas_equalTo(10+i*120);
        }];
        XianView12.backgroundColor=_LightGrey;
    }
}
-(void)pushYHPJViewController:(UITapGestureRecognizer *)tap{
    YHPJViewController *YHPJ=[[YHPJViewController alloc] init];
    YHPJ.tableArr=[_dic objectForKey:@"evaluate"];
    [ZQTools pushNextViewController:self.viewController andRootController:YHPJ];
}

@end
